<!--
 * @Author: 王灿
 * @Date: 2019-11-05 12:53:03
 * @Description: table标题栏
 -->
 <template>
  <div class="jq-title">
    <div class="jq-title__left">
      <span></span>
      <span>{{ title.label }}</span>
    </div>
    <div class="jq-title__right" v-if="title.flag">
      <el-input
        v-if="title.searchFlag"
        placeholder="请输入名称"
        prefix-icon="el-icon-search"
        v-model="name"
      ></el-input>
      <el-button icon="el-icon-plus" @click="onClick">新增</el-button>
    </div>
  </div>
</template>

 <script>
export default {
  name: 'JqTitle',
  props: {
    title: {
      type: Object,
      default: () => {
        return {
          // 导航标题
          label: {
            type: String,
            default: ''
          },
          // 创建按钮
          flag: {
            type: Boolean,
            default: false
          },
          // name模糊搜索
          searchFlag: {
            type: Boolean,
            default: false
          }
        }
      }
    },
    // name
    searchKey: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      name: ''
    }
  },
  watch: {
    // 监听tabs点击 searchKey 刷新
    searchKey() {
      if (this.searchKey) {
        this.name = ''
      }
    },
    // 监听name模糊搜索事件
    name() {
      this.$emit('onChangeName', this.name)
    }
  },
  methods: {
    // 创建按钮触发父组件相应事件
    onClick() {
      let data = { isShow: !this.flag }
      this.$emit('addTableRow', data)
    }
  }
}
</script>

 <style lang="scss" scoped>
.jq-title {
  @include row;
  justify-content: space-between;
  width: 100%;
  box-sizing: border-box;
  padding: 10px;
  background: #fff;
  .jq-title__left {
    span {
      font-weight: 500;
      background: #fff;
      color: #333;
      &:first-child {
        display: inline-block;
        width: 6px;
        height: 14px;
        background-color: $navBarBg;
        border-radius: 3px;
        margin-right: 10px;
        position: relative;
        top: 1px;
      }
    }
  }
  .jq-title__right {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    .el-input {
      &.el-input--prefix {
        width: 200px !important;
        margin-right: 15px;
        .el-input__inner {
          height: 32px !important;
        }
      }
    }
    .el-button {
      background: $bgColor;
      border-color: $bgColor;
      color: #fff;
      line-height: 30px;
      padding: 0 10px;
    }
  }
}
</style>

<style lang="scss">
.jq-title__right {
  .el-input__inner {
    height: 32px !important;
  }
  .el-input__icon {
    line-height: 32px !important;
  }
}
</style>